import type { ComponentPublicInstance } from "vue";
import type { SelectType } from "@/components/Select/interface/";
import type { SwitchType } from "@/components/Switch/interface/";
import type { NumberType } from "@/components/Number/interface/";
import type { InputType } from "@/components/Input/interface/";
import From from "../index.vue";
export namespace FormType {
  // 类型
  type Type = "select" | "switch" | "number" | "input";

  // 方向
  type Position = "left" | "right" | "top";

  // 表单检验项
  export interface Rules_Item {
    trigger: "blur" | "change";
    validator?: (rule: any, value: any, callback: any) => void; // 自定义验证
    required?: boolean; // 能否为空
    message?: string; // 提示信息
    max?: number; // 最大长度
    min?: number; // 最小长度
    pattern?: RegExp;
  }
  export interface Rules {
    [key: string]: Rules_Item[];
  }

  // 表单项
  export interface FormItem {
    type?: Type;
    select?: SelectType.Props; // 下拉
    switch?: SwitchType.Props; // 开关
    number?: NumberType.Props; // 数字输入框
    input?: InputType.Props; // 输入框
  }

  // 提交按钮回调数据
  export interface Callback<T> {
    is: boolean;
    v: T;
  }

  //   汇总
  export interface Props {
    data: any; // 数据
    columns: ColumnsProps[]; // 表单内容
    rules?: Rules; // 约束
    inline?: boolean; //行内表单
    labelSymbol?: string; // 显示的符号
    labelPosition?: Position; // label 方向
    labelWidth?: number | string; // label 宽度
  }

  export type FomrInstance = Omit<
    InstanceType<typeof From>,
    keyof ComponentPublicInstance | keyof Props
  >;
}
